package com.settlement.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.common.annotation.PreventDuplicateSubmit;
import com.settlement.system.common.result.PageResult;
import com.settlement.system.common.result.Result;
import com.settlement.system.model.entity.SysBillLock;
import com.settlement.system.model.form.BillLockForm;
import com.settlement.system.model.query.BillLockPageQuery;
import com.settlement.system.service.SysBillLockService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 核销锁账表 前端控制器
 * </p>
 *
 * @author huangrensen
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/api/v1/billLock")
@RequiredArgsConstructor
public class SysBillLockController {
    private final SysBillLockService sysBillLockService;

    @Operation(summary = "核销锁账分页列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/page")
    public PageResult<SysBillLock> getBillLockPage(@ParameterObject BillLockPageQuery queryParams) {
        Page<SysBillLock> result = sysBillLockService.getBillLockPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "保存核销锁账", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping
    @PreAuthorize("@ss.hasPerm('sys:billLock:save')")
    @PreventDuplicateSubmit
    public Result saveBillLock(@RequestBody @Valid BillLockForm storeForm) {
        boolean result = sysBillLockService.saveBillLock(storeForm);
        return Result.judge(result);
    }

    @Operation(summary = "核销锁账表单数据", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/{billLockId}/form")
    public Result<SysBillLock> getBillLockFormData(@Parameter(description = "核销锁账ID") @PathVariable Long billLockId) {
        SysBillLock sysBillLock = sysBillLockService.getBillLockFormData(billLockId);
        return Result.success(sysBillLock);
    }

    @Operation(summary = "删除核销锁账", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('sys:billLock:delete')")
    public Result deleteStores(@Parameter(description = "核销锁账ID，多个以英文逗号(,)分割") @PathVariable String ids) {
        boolean result = sysBillLockService.deleteBillLock(ids);
        return Result.judge(result);
    }
}
